﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ResxLocalizationEditor.CommonPanel;
using Google.GData.Documents;
using Google.GData.Client;
using ResxLocalizationEditor.GoogleImport;
using Google.Documents;

namespace ResxLocalizationEditor.GoogleExport {
    partial class GoogleDocsExport : WizardForm {

        GoogleImport.FolderVisualizer _panelFolder;
        ExportingPanel _panelExport;

        ResourceSet _resources;

        public GoogleDocsExport(ResourceSet resources) {
            InitializeComponent();

            _resources = resources;

            loginPanel1.AcceptButton.Click += new EventHandler(LoginAccept_click);

            _panelFolder = new GoogleImport.FolderVisualizer();
            _panelFolder.ImportButton.Text = "Export";
            _panelFolder.ImportButton.Click += new EventHandler(FolderSelection_click);

            _panelExport = new ExportingPanel();
        }

        string _username;
        string _password;

        void LoginAccept_click(object sender, EventArgs e) {
            _username = loginPanel1.Username;
            _password = loginPanel1.Password;

            SwitchPanel(loginPanel1, _panelFolder);
            _panelFolder.LoadFolders(_username, _password);
        }

        void FolderSelection_click(object sender, EventArgs e) {
            var folder = _panelFolder.SelectedDocument;
            if (folder == null)
                throw new ArgumentNullException("No folder selected.");

            SwitchPanel(_panelFolder, _panelExport);
            _panelExport.Export(_username, _password, _resources, folder);
        }

    }
}
